/**
 *	flowtodo
 *	开发者：雨中磐石
 *	地址：www.rockoa.com
 *	日期：2023-07-31
 */

package com.framework.Module.flow.flowtodo;


import com.framerock.db.DB;
import com.framerock.baselib.Json;
import com.framerock.baselib.Patter;
import com.framerock.baselib.Rock;
import com.framework.ACore.Model;
import com.framework.Flow.FlowListener;
import com.framework.Model.ModelMode;

import java.util.ArrayList;
import java.util.Map;

public class FlowListenerflowtodo extends FlowListener {


    public Boolean onModejs() {
        return true;
    }

    @Override
    public Boolean onRemind() { return true; }


    @Override
    public Boolean onisAdd() {
        if(mRequest.USERTYPE>0)return true;
        return super.onisAdd();
    }

    @Override
    public Boolean onisEdit() {
        if(mRequest.USERTYPE>0)return true;
        return super.onisEdit();
    }

    public Map<String, String> onDataafter()
    {
        Map<String, String> da = Rock.getMap();
        if(mRequest.LOADCI==1){
            String where = "`isxt`=2";
            if(mRequest.COMPANYBOOL){
                String inwhere = DB.dbSql(DB.chuliPerfix("flowunit"), "modeid", "`cid`="+mRequest.COMPANYID+" AND `modeid`>0");
                where += " AND `id` IN("+inwhere+")";
            }
            da.put("modearr", Json.getListString(ModelMode.get(this.nDb).getMdearr(where)));
        }

        return da;
    }

    public Map<String, String> onDatabefore(){
        String where  = "";
        int modeid = Integer.parseInt(mRequest.get("modeid", "0"));
        if(modeid>0)where  = "`modeid`="+modeid+"";
        return Rock.getMap(new String[]{
                "where", where
        });
    }

    public ArrayList<Map<String, String>> onStore(String action, String params) {
        if(action.equals("wheredata"))return wheredata();
        return null;
    }

    //读取条件数据源
    public ArrayList<Map<String, String>> wheredata()
    {
        String mkid = mRequest.get("mkid");
        if(Rock.isEmpt(mkid) || !Patter.isnumber(mkid))return null;

        ArrayList<Map<String, String>> rows = Model.get(this.nDb, "flowwhere").getAll("`modeid`="+mkid+"", "*", "`sort` asc");
        storeList = Rock.getMapList();
        Map<String, String> da;
        if(rows!=null)for(int i=0; i<rows.size() ;i++){
            da = rows.get(i);
            if(!Rock.isEmpt(da.get("num")))adddList(da.get("num"), da.get("name"), da.get("num"));
        }
        return storeList;
    }
}
